package dtomap

import (
	"fmt"
	"strings"
)

const (
	classStart = "public class %s {"

	classField = "%s public %s %s {get;set;}"

	classEnd = "}"

	separator = "\r\n"

	NewClassAStart = "new A(){"

	NewClassAField = "%s %s=temp.%s,"
)

type DestClass struct {
	Name   string
	Fields []DestField
}

type DestField struct {
	Name string
	Type string
}

func (df *DestField) String() string {
	return fmt.Sprintf(classField, separator, df.Type, df.Name)
}

func (df *DestField) NewClassString() string {
	return fmt.Sprintf(NewClassAField, separator, df.Name, df.Name)
}

/*
   public class A{
     public int SysNo{get;set;}
     public int SysNo2{get;set;}
   }
*/
func (dc *DestClass) String() string {
	sb := strings.Builder{}
	sb.WriteString(fmt.Sprintf(classStart, dc.Name))
	for _, field := range dc.Fields {
		sb.WriteString(field.String())
	}
	sb.WriteString(separator)
	sb.WriteString(classEnd)
	return sb.String()
}

/*
  new A(){
   SysNo=tmp.SysNo,
   SysNo2=tmp.SysNo2
 }
*/
func (dc *DestClass) NewClassString() string {
	sb := strings.Builder{}
	sb.WriteString(NewClassAStart)
	for _, field := range dc.Fields {
		sb.WriteString(field.NewClassString())
	}
	sb.WriteString(separator)
	sb.WriteString(classEnd)
	return sb.String()

}
